import prompt from '@system.prompt';
import router from '@system.router';
import media from '@ohos.multimedia.media';
import deviceManager from '@ohos.distributedHardware.deviceManager';

export default {
    data: {
        autoplay: false, // 是否自动播放
        videoId: 'video', // 播放器id
        url: '/common/videos/video1.mp4', // 视频地址
        controlShow: true, // 是否显示控制栏
        isFullScreenChange: false, // 是否全屏
        audioRecorder: null,
        startTime:0,
        currTime:0,
        isRecord:false,
    },
    onInit(){
    },
// 播放进度变化调用
    timeUpdate(e) {
        this.currTime=e.currenttime;
    },

// 自带组件进入全屏和退出全屏
    fullScreenChange(e) {
        if (e.fullscreen === 1) {
            this.isFullScreenChange = true;
        } else {
            this.isFullScreenChange = false;
        }
    },
// 长按屏幕视频进入和退出全屏时触发事件
    longPressFullScreenChange() {
        if (this.isFullScreenChange) { // 全屏
            this.$element('video').exitFullscreen();
            this.isFullScreenChange = false;
        } else { // 非全屏
            this.$element('video').requestFullscreen({ screenOrientation : 'default' });
            this.isFullScreenChange = true;
        }
    },

// dialog确定
    confirm() {
        this.$element('video').start();
        this.$element('confirmDialog').close();
    },
// dialog取消
    cancel() {
        this.$element('confirmDialog').close();
    },
// 弹框
    showPrompt(msg) {
        prompt.showToast({
            message: msg,
            duration: 1000,
        });
    },
// 点击视频
    hideControls() {
        this.controlShow = !this.controlShow;
    },
    //返回
    back(){
        router.back();
    },

    projection(){
        let actionData = {
            url:this.url,
            startTime:this.currTime
        };
        let target = {
            bundleName: "com.example.ktv_js_2",
            abilityName: "com.example.ktv_js_2.MainAbility",
            data: actionData,
            url:"pages/largeScreen/largeScreen"
        };
        let result = FeatureAbility.startAbility(target);
    },
    /*async recordStart(){
        var actionData = {};
        var action = {};
        action.bundleName = 'com.example.ktv_js_2';
        action.abilityName = 'com.example.ktv_js_2.SoundRecordServiceAbility';
        action.messageCode = 100;
        action.data = actionData;
        //abilityType: 0-Ability; 1-Internal Ability
        action.abilityType = 0;
        var result = await FeatureAbility.callAbility(action);
        var ret = JSON.parse(result);
        if (ret.code == 0) {
            this.isRecord=true;
            console.info('plus result is:' + JSON.stringify(ret.abilityResult));
        } else {
            console.error('plus error code:' + JSON.stringify(ret.code));
        }
    },
    async recordStop(){
        var actionData = {};
        var action = {};
        action.bundleName = 'com.example.ktv_js_2';
        action.abilityName = 'com.example.ktv_js_2.SoundRecordServiceAbility';
        action.messageCode = 200;
        action.data = actionData;
        //abilityType: 0-Ability; 1-Internal Ability
        action.abilityType = 0;
        var result = await FeatureAbility.callAbility(action);
        var ret = JSON.parse(result);
        if (ret.code == 0) {
            this.isRecord=false;
            console.info('plus result is:' + JSON.stringify(ret.abilityResult));
        } else {
            console.error('plus error code:' + JSON.stringify(ret.code));
        }
    },
    async onDestroy(){
        var actionData = {};
        var action = {};
        action.bundleName = 'com.example.ktv_js_2';
        action.abilityName = 'com.example.ktv_js_2.SoundRecordServiceAbility';
        action.messageCode = 300;
        action.data = actionData;
        //abilityType: 0-Ability; 1-Internal Ability
        action.abilityType = 0;
        var result = await FeatureAbility.callAbility(action);
        var ret = JSON.parse(result);
        if (ret.code == 0) {
            this.isRecord=false;
            console.info('plus result is:' + JSON.stringify(ret.abilityResult));
        } else {
            console.error('plus error code:' + JSON.stringify(ret.code));
        }
    }*/
}
